package com.qf.hospital.handler;

import com.qf.hospital.enums.HospitalExceptionEnums;
import com.qf.hospital.exception.HospitalException;
import com.qf.hospital.vo.R;
import org.apache.shiro.authc.IncorrectCredentialsException;
import org.apache.shiro.authc.UnknownAccountException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author zjw
 * @description  异常处理器,不要忘记扫描注解
 * @date 2021/10/15 14:34
 */
@RestControllerAdvice
public class HospitalExceptionHandler {

    @ExceptionHandler({IncorrectCredentialsException.class, UnknownAccountException.class})
    public R credentialsException(){
        return R.error(HospitalExceptionEnums.USERNAME_PASSWORD_ERROR,"");
    }

    @ExceptionHandler(HospitalException.class)
    public R hospitalException(HospitalException ex){
        return R.error(ex.getCode(),ex.getMessage());
    }
}
